package com.ruoyi.web.controller.counter;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.counter.domain.Tools;
import com.ruoyi.counter.service.IToolsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.util.List;

/**
 * 工具(设备）Controller
 *
 * @author xll
 * @date 2021-07-26
 */
@RestController
@RequestMapping("/counter/tools")
public class ToolsController extends BaseController
{
    @Autowired
    private IToolsService toolsService;

    /**
     * 查询工具(设备）列表
     */
    @PreAuthorize("@ss.hasPermi('counter:tools:list')")
    @GetMapping("/list")
    public TableDataInfo list(Tools tools)
    {

        startPage();
        List<Tools> list = toolsService.selectToolsList(tools);
        return getDataTable(list);
    }

    /**
     * 导出工具(设备）列表
     */
    @PreAuthorize("@ss.hasPermi('counter:tools:export')")
    @Log(title = "工具(设备）", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Tools tools)
    {
        List<Tools> list = toolsService.selectToolsList(tools);
        ExcelUtil<Tools> util = new ExcelUtil<Tools>(Tools.class);
        return util.exportExcel(list, "工具(设备）数据");
    }

    /**
     * 获取工具(设备）详细信息
     */
    @PreAuthorize("@ss.hasPermi('counter:tools:query')")
    @GetMapping(value = "/{toolid}")
    public AjaxResult getInfo(@PathVariable("toolid") Long toolid)
    {
        return AjaxResult.success(toolsService.selectToolsById(toolid));
    }

    /**
     * 新增工具(设备）
     */
    @PreAuthorize("@ss.hasPermi('counter:tools:add')")
    @Log(title = "工具(设备）", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Tools tools)
    {
        return toAjax(toolsService.insertTools(tools));
    }

    /**
     * 修改工具(设备）
     */
    @PreAuthorize("@ss.hasPermi('counter:tools:edit')")
    @Log(title = "工具(设备）", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Tools tools) throws ParseException {
        try{
            return toAjax(toolsService.updateTools(tools));
        }
        catch(Exception ex)
        {
            //notodo
        }
        return null;
    }

    /**
     * 删除工具(设备）
     */
    @PreAuthorize("@ss.hasPermi('counter:tools:remove')")
    @Log(title = "工具(设备）", businessType = BusinessType.DELETE)
	@DeleteMapping("/{toolids}")
    public AjaxResult remove(@PathVariable Long[] toolids)
    {
        return toAjax(toolsService.deleteToolsByIds(toolids));
    }
}
